package com.mallcai.bigdata.ladon.dpl.mapper.peekdata.provider;

import com.mallcai.bigdata.ladon.dpl.entity.peekdata.PeekRule;
import com.mallcai.bigdata.ladon.dpl.mapper.BaseSqlProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
public class PeekRuleSqlProvider extends BaseSqlProvider<PeekRule> {
    public static final String TB_PEEK_RULE = "pd_peek_rule";


    @Override
    public String getTableName() {
        return TB_PEEK_RULE;
    }

    @Override
    public Map<String, String> getInsertColumns() {
        Map<String, String> map = new LinkedHashMap<>();
        map.put("peek_id", "#{peekId}");
        map.put("meta_id", "#{metaId}");
        map.put("field_name", "#{fieldName}");
        map.put("rule", "#{rule}");
        map.put("value", "#{value}");
        return map;
    }

    @Override
    public Map<String, String> getUpdateColumns() {
        Map<String, String> map = new LinkedHashMap<>();
        map.put("peekId", "peek_id");
        map.put("metaId", "meta_id");
        map.put("fieldName", "field_name");
        map.put("rule", "rule");
        map.put("value", "value");
        return map;
    }

    public String getByPeekId(@Param("peekId") Long peekId) {
        return new SQL() {
            {
                SELECT("tb_pr.*,tb_mm.data_type AS data_type,tb_mm.original_data_type AS original_data_type, tb_mm.show_name AS show_name, tb_mm.tag_id AS tagId");
                LEFT_OUTER_JOIN(ModelMetaSqlProvider.TB_MODEL_META + " tb_mm  ON tb_mm.id = tb_pr.meta_id ");
                FROM(TB_PEEK_RULE + " tb_pr ");
                WHERE(" tb_pr.peek_id = #{peekId}");
            }
        }.toString();
    }
}
